package ee.maoinvest.frontend.controller.eventfinders;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

public class EnterpriseRelationsWithElectricityMetersAndContractsMenuEventFinder implements EventFinder
{
	private final String EMPTY_STRING = "";
	private Logger logger = Logger.getLogger(EnterpriseRelationsWithElectricityMetersAndContractsMenuEventFinder.class);
	
	@Override
	public String findEvent(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException 
	{
		String event = "undefined";
		
		try 
		{
			String mode = request.getParameter("mode");
			String submode = request.getParameter("submode");
			String formSubmitted = request.getParameter("formSubmitted");
			if (mode.equals("administerEnterpriseRelationsWithElectricityMetersAndContractsPage") 
					&& submode != null && !submode.equals(EMPTY_STRING))
			{
				event = "undefined";
				
				if (submode.equals("manageEnterprisesRelationsWithElectricityMetersAndContractsPage"))
				{
					event = "manageEnterprisesRelationsWithElectricityMetersAndContractsPage";
				}
				
				if (submode.equals("insertNewContractBetweenEnterpriseAndElectricityMeterPage"))
				{
					event = "insertNewContractBetweenEnterpriseAndElectricityMeterPage";
				}
				
				if (submode.equals("manageElectricityContractRelationsWithElectricityMetersAndEnterprisesPage"))
				{
					event = "manageElectricityContractRelationsWithElectricityMetersAndEnterprisesPage";
				}
				
				
				if (submode.equals("manageEnterprisesRelationsWithElectricityMetersAndContractsPage")
						&& formSubmitted != null
						&& formSubmitted.equals("removeEnterpriseContractWithElectricityMeterForm"))
				{
					event = "removeEnterpriseContractWithElectricityMeterCommandFormPostEvent";
				}
				
				if (submode.equals("insertNewContractBetweenEnterpriseAndElectricityMeterPage")
						&& formSubmitted != null
						&& formSubmitted.equals("insertNewContractBetweenEnterpriseAndElectricityMeterForm"))
				{
					event = "insertNewContractBetweenEnterpriseAndElectricityMeterFormPostEvent";
				}
				
				
				if (submode.equals("manageElectricityContractRelationsWithElectricityMetersAndEnterprisesPage")
						&& formSubmitted != null
						&& formSubmitted.equals("removeElectricityContractRelationWithElectricityMeterAndEnterpriseForm"))
				{
					event = "removeElectricityContractRelationsWithElectricityMetersAndEnterprisesFormPostEvent";
				}
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return event;
	}
}